# -*- coding: utf-8 -*-

import mod.server.extraServerApi as serverApi

from enchantBase import EnchantBase

comp = serverApi.GetEngineCompFactory()
levelId = serverApi.GetLevelId()

DAMAGE_MULTIPLIER = [1.5, 2.0, 2.5]


class Betray(EnchantBase):
    def __init__(self, system, playerId, enchantData, levels):
        EnchantBase.__init__(self, system, playerId, enchantData, levels)
        pass

    def isArmorEnchant(self):
        return False

    def onEnter(self):
        self.mSystem.ListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(),
                                    'ActuallyHurtServerEvent', self, self.on_back_stab)
        pass

    def onExit(self):
        self.mSystem.UnListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(),
                                      'ActuallyHurtServerEvent', self, self.on_back_stab)
        pass

    def on_back_stab(self, args):
        player_id = args['srcId']
        if player_id != self.playerId:
            return
        victim = args['entityId']
        comp_game = comp.CreateGame(victim)
        if comp_game.CanSee(victim, player_id):
            return
        enchant_level = self.levels[0]
        dmg_f = args['damage_f']
        args['damage_f'] *= DAMAGE_MULTIPLIER[enchant_level - 1]
        pass
